<template>
	<view class="login">
		<!-- 使用之前请配置好相关appid -->
		<view class="btn" @click="wxloginForGetOpenId">
			微信登录
		</view>
		<view class="btn" @click="qqloginForGetUserId">
			QQ登录
		</view>
	</view>
</template>

<script>
	export default{
		methods:{
			// wx登录
			wxloginForGetOpenId(){
				let openId = 'null';
				var that = this
				uni.login({
					provider: 'weixin',
					success: function (loginRes) {
						// console.log(loginRes.authResult);
						uni.getUserInfo({
							provider: 'weixin',
							success: function (infoRes) {
								// // console.log(infoRes)
								// console.log('用户昵称为：' + infoRes.userInfo.nickName);
								let string = infoRes.userInfo.openId
								openId=string
								// that.wxLogin(openId);  // 开始调用后端的登录接口
							}
					  });
				  }
				});
			},
			// qq登录
			qqloginForGetUserId(){
				let sourceId = '';
				var that = this
				uni.login({
					provider: "qq",
					success: (resp) => {
						// console.log(resp.toString())
						sourceId=resp.authResult.openid;
						// console.log(sourceId)
						// that.qqLogin(sourceId);  // 开始调用后端的登录接口
						
					},
					fail: (err) => {
						// console.log(err.toString())
					},
					complete:()=>{
					
					}
				})
			},
		}
	}
</script>

<style>
	.btn{
		background: #976BF8;
		border-radius: 20rpx;
		height: 70rpx;
		line-height:  70rpx;
		width: 90%;
		margin: auto;
		display: block;
		text-align: center;
		color: #FFFFFF;
		margin-bottom: 20rpx;
	}
</style>
